
import { axiosInstance } from "..";
import { encrypt } from "../../../../utils/secret";

export interface UserLogin{
    username: string;
    password: string;
}

function Login(user:UserLogin){
    return new Promise((resolve,reject)=>{
        const username:string = user.username.trim()
        const password:string = encrypt(user.password.trim())
        axiosInstance().post("/material/author/login",{username,password}).then(
            (res:any)=>{
                resolve(res)
            },
            (err:any)=>{
                reject(err)
            }
        )
    })
}

function MuteLogin(user:UserLogin){
    return new Promise((resolve,reject)=>{
        const username:string = user.username.trim()
        const password:string = encrypt(user.password.trim())
        axiosInstance().post("/material/author/mutelogin",{username,password}).then(
            (res:any)=>{
                resolve(res)
            },
            (err:any)=>{
                reject(err)
            }
        )
    })
}

function getUserInfo(username:string){
    return new Promise((resolve,reject)=>{
        axiosInstance().post("/material/author/userinfo",{username}).then(
            (res:any)=>{
                resolve(res)
            },
            (err:any)=>{
                reject(err)
            }
        )
    })
}

export{
    Login,getUserInfo,MuteLogin
}